class Event {
    constructor() {
        this.ve = {
            'abort': [],
            'canplay': [],
            'canplaythrough': [],
            'durationchange': [],
            'emptied': [],
            'ended': [],
            'error': [],
            'loadeddata': [],
            'loadedmetadata': [],
            'loadstart': [],
            'mozaudioavailable': [],
            'pause': [],
            'play': [],
            'playing': [],
            'progress': [],
            'ratechange': [],
            'seeked': [],
            'seeking': [],
            'stalled': [],
            'suspend': [],
            'timeupdate': [],
            'volumechange': [],
            'waiting': []
        }
        this.e = {
            ...this.ve, ...{
                pip: [],
                resize: [],
                danmuLoad: [],
                danmuSeek: [],
                destroy: [],
            }
        }
    }

    on(name, callback) {
        if (!(this.e[name] instanceof Array)) return
        if (typeof callback !== 'function') return
        this.e[name].push(callback)
    }

    trigger(name, info) {
        if (!(this.e[name] instanceof Array)) return
        for (let i = 0; i < this.e[name].length; i++) {
            this.e[name][i](info)
        }
    }

    remove(name, callback) {
        if (!(this.e[name] instanceof Array)) return
        if (typeof callback === 'function') this.e[name].remove(callback)
        if (callback === undefined || callback === null) this.e[name].length = 0
    }
}

export default () => new Event()
